package com.wc.alorithm_blue_bridge._动态规划.背包问题.Q1177;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description 小明的背包4
 * https://www.lanqiao.cn/problems/1177/learning/?page=3&first_category_id=1&sort=students_count&second_category_id=8
 * @Date Created in 2023/11/7-10:57
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int maxS = 2000;
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] dp = new int[n][m + 1];
        int[] ws = new int[n];
        int[] vs = new int[n];
        int[] ss = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = sc.nextInt();
            vs[i] = sc.nextInt();
            ss[i] = sc.nextInt();
            if (ss[i] == 0) {
                ss[i] = maxS;
            }
        }

        for (int j = ws[0]; j <= m; j++) {
            int num = Math.min(j / ws[0], ss[0]);
            dp[0][j] = num * vs[0];
        }

        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= m; j++) {
                if (j >= ws[i]) {
                    int num = Math.min(j / ws[i], ss[i]);
                    int maxV = 0;
                    for (int k = 1; k <= num; k++) {
                        maxV = Math.max(maxV, dp[i - 1][j - k * ws[i]] + k * vs[i]);
                    }
                    dp[i][j] = Math.max(maxV, dp[i - 1][j]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[n - 1][m]);
    }

    static class Input {
        public StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }
}
